package com.zdb.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.zdb.service.FileService;
import com.zdb.util.MinioUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class FileServiceImpl implements FileService {
    private static final Logger log = LoggerFactory.getLogger(FileServiceImpl.class);
    @Autowired
    private MinioUtils minioUtils;
    @Override
    public String uploadFile(MultipartFile file) {
        if (ObjectUtil.isEmpty( file)){
            return null;
        }
        try {
            String url = minioUtils.getPresignedUrl(file.getOriginalFilename(), 60 * 60 * 24);
            log.info("上传文件成功，url:{}", url);
            minioUtils.uploadFile(file.getOriginalFilename(), file);
            return url;
        } catch (Exception e) {
            log.error("上传文件失败", e);
        }
        return null;
    }
}
